package Model;
import java.util.*;

public class DeleteTaskCommand implements Command
{
	//attributes
	private Task deletedtask;
	private ArrayList<Task> TasksPointer;
    private boolean undo;

	
	//-----------------------------------------------------------------------------------
	//-----------------------------------------------------------------------------------
	//-----------------------------------------------------------------------------------
	
	public ArrayList<Task> getTasksPointer() {
		return TasksPointer;
	}

	public void setTasksPointer(ArrayList<Task> tasksPointer) {
		TasksPointer = tasksPointer;
	}	
    
    public DeleteTaskCommand (ArrayList<Task> PointerToTasks)
	{
		TasksPointer=PointerToTasks;
        undo=false;
	}
	
	//-----------------------------------------------------------------------------------
	//-----------------------------------------------------------------------------------
	//-----------------------------------------------------------------------------------
	
	public void execute(String taskName)
	{
		for(int i = 0; i < TasksPointer.size(); ++i)
		{
			if(TasksPointer.get(i).getName().equals(taskName))
			{
                deletedtask = TasksPointer.get(i);
				TasksPointer.remove(i);
				break;
			}
		}
	}
	
	//-----------------------------------------------------------------------------------
	//-----------------------------------------------------------------------------------
	//-----------------------------------------------------------------------------------
	
	//implmentation due to interface
	public void undo()
	{
		if(deletedtask !=null && undo==false)
		{
			TasksPointer.add(deletedtask);
            undo=true;
		}
	}
	
	//-----------------------------------------------------------------------------------
	//-----------------------------------------------------------------------------------
	//-----------------------------------------------------------------------------------
	
	public void redo()
	{
		if(deletedtask !=null && undo)
		{
			TasksPointer.remove(deletedtask);
            undo=false;
		}
	}
	
	//-----------------------------------------------------------------------------------
	//-----------------------------------------------------------------------------------
	//-----------------------------------------------------------------------------------
}
